package com.xxl.config;

import com.xxl.interceptor.AuthenticationInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author xxl
 * @date 2023/3/14
 */
@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {
    @Resource
    AuthenticationInterceptor authenticationInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(authenticationInterceptor);
        interceptorRegistration
                .addPathPatterns(
                        //拦截所有请求
                        "/**"
                ).excludePathPatterns(
                        //不拦截首页
                         "/index",
                        //不拦截首页
                        "/",
                        //不拦截去往登录页
                        "/view/login.html",
                        //不拦截去往登录页
                        "/view/login",
                        //不拦截登录请求
                        "/user/login",
                        //静态资源(固定写法)
                        "/**/*.js",
                        "/**/*.css",
                        "/**/*.png",
                        "/**/*.jpg"
                );

    }
}
